﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using System.Text;

public partial class settlement : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnRefundSettlement_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        StringBuilder sb = new StringBuilder();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "sp_refund_settlement";
        SqlParameter para = cmd.Parameters.AddWithValue("@time_from", txtTimeFrom.Text);
        para = cmd.Parameters.AddWithValue("@time_to", txtTimeTo.Text);
        int i;
        i = TinyDAL.Exec(ref cmd, ref dt);
        i = dt.Rows.Count;
        if (i == 0)
        {
            return;
        }

        Page.Response.Clear();
        Page.Response.Buffer = true;
        Page.Response.Charset = "GB2312";
        Page.Response.AppendHeader("Content-Disposition", "attachment;filename=RefundSettlement.txt");
        Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "text/plain";
        this.EnableViewState = false;
        System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
        sb.Append("order\tpax_sn\ttrip_sn\tori\tdes\tairline\tflt_no\tflt_date\tvirtual\top_airline\top_flt_no\tcabin\tclass\tfare_code\tage\tpay_entity\tpay_office\tpay_time\tpay_type\tpay_currency\tfare_currency\tprice\tsurcharge\tfare_roe\ttax_currency\ttaxes\ttax_roe\tcancel_type\tcancel_time\tcancel_entity\tcancel_office\trefund_fare\trefund_time\trefund_entity\trefund_office\r\n");
        for (i = 1; i <= dt.Rows.Count; i++)
        {
            sb.Append(dt.Rows[i - 1]["bk_id"].ToString() + "\t" + dt.Rows[i - 1]["pax_sn"].ToString() + "\t" + dt.Rows[i - 1]["trip_sn"].ToString() + "\t" + dt.Rows[i - 1]["ori_city"].ToString() + "\t" + dt.Rows[i - 1]["des_city"].ToString() + "\t");
            sb.Append(dt.Rows[i - 1]["airline"].ToString() + "\t" + dt.Rows[i - 1]["flt_no"].ToString() + "\t" + dt.Rows[i - 1]["flt_date"].ToString() + "\t" + dt.Rows[i - 1]["virtual"].ToString() + "\t" + dt.Rows[i - 1]["op_airline"].ToString() + "\t" + dt.Rows[i - 1]["op_flt_no"].ToString() + "\t" + dt.Rows[i - 1]["cabin"].ToString() + "\t" + dt.Rows[i - 1]["class"].ToString() + "\t" + dt.Rows[i - 1]["fare_code"].ToString() + "\t" + dt.Rows[i - 1]["age_type"].ToString() + "\t");
            sb.Append(dt.Rows[i - 1]["pay_entity"].ToString() + "\t" + dt.Rows[i - 1]["pay_office"].ToString() + "\t" + dt.Rows[i - 1]["pay_time"].ToString() + "\t" + dt.Rows[i - 1]["pay_type"].ToString() + "\t" + dt.Rows[i - 1]["pay_currency"].ToString() + "\t" + dt.Rows[i - 1]["fare_currency"].ToString() + "\t" + dt.Rows[i - 1]["price"].ToString() + "\t" + dt.Rows[i - 1]["surcharge"].ToString() + "\t" + dt.Rows[i - 1]["fare_roe"].ToString() + "\t");
            sb.Append(dt.Rows[i - 1]["tax_currency"].ToString() + "\t" + dt.Rows[i - 1]["taxes"].ToString() + "\t" + dt.Rows[i - 1]["tax_roe"].ToString()+"\t");
            sb.Append(dt.Rows[i - 1]["cancel_type"].ToString() + "\t" + dt.Rows[i - 1]["cancel_time"].ToString() + "\t" + dt.Rows[i - 1]["cancel_entity"].ToString() + "\t" + dt.Rows[i - 1]["cancel_office"].ToString() + "\t" + dt.Rows[i - 1]["refund_fare"].ToString()+ "\t" + dt.Rows[i - 1]["refund_time"].ToString()+ "\t" + dt.Rows[i - 1]["refund_entity"].ToString()+ "\t" + dt.Rows[i - 1]["refund_office"].ToString());

            sb.Append("\r\n");
        }
        Page.Response.Write(sb.ToString());
        Page.Response.End();
    }
    protected void btnSaleSettlement_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        StringBuilder sb = new StringBuilder();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "sp_sale_settlement";
        SqlParameter para = cmd.Parameters.AddWithValue("@time_from", txtTimeFrom.Text);
        para = cmd.Parameters.AddWithValue("@time_to",txtTimeTo.Text);
        int i;
        i=TinyDAL.Exec(ref cmd,ref dt);
        i=dt.Rows.Count;
        if (i == 0)
        {
            return;
        }

        Page.Response.Clear();
        Page.Response.Buffer = true;
        Page.Response.Charset = "GB2312";
        Page.Response.AppendHeader("Content-Disposition", "attachment;filename=SaleSettlement.txt");
        Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.ContentType = "text/plain";
        this.EnableViewState = false;
        System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
        sb.Append("order\tpax_sn\ttrip_sn\tori\tdes\tairline\tflt_no\tflt_date\tvirtual\top_airline\top_flt_no\tcabin\tclass\tfare_code\tage\tpay_entity\tpay_office\tpay_time\tpay_type\tpay_currency\tfare_currency\tprice\tsurcharge\tfare_roe\ttax_currency\ttaxes\ttax_roe\r\n"); 
        for (i = 1; i <= dt.Rows.Count; i++)
        {
            sb.Append(dt.Rows[i-1]["bk_id"].ToString()+"\t"+dt.Rows[i-1]["pax_sn"].ToString()+"\t"+dt.Rows[i-1]["trip_sn"].ToString()+"\t"+dt.Rows[i-1]["ori_city"].ToString()+"\t"+dt.Rows[i-1]["des_city"].ToString()+"\t");
            sb.Append(dt.Rows[i - 1]["airline"].ToString() + "\t" + dt.Rows[i - 1]["flt_no"].ToString() + "\t" + dt.Rows[i - 1]["flt_date"].ToString() + "\t" + dt.Rows[i - 1]["virtual"].ToString() + "\t" + dt.Rows[i - 1]["op_airline"].ToString() + "\t" + dt.Rows[i - 1]["op_flt_no"].ToString() + "\t" + dt.Rows[i - 1]["cabin"].ToString() + "\t" + dt.Rows[i - 1]["class"].ToString() + "\t" + dt.Rows[i - 1]["fare_code"].ToString() + "\t" + dt.Rows[i - 1]["age_type"].ToString() + "\t"); 
            sb.Append(dt.Rows[i - 1]["pay_entity"].ToString() + "\t" + dt.Rows[i - 1]["pay_office"].ToString() + "\t" + dt.Rows[i - 1]["pay_time"].ToString() + "\t" + dt.Rows[i - 1]["pay_type"].ToString() + "\t" + dt.Rows[i - 1]["pay_currency"].ToString() + "\t" + dt.Rows[i - 1]["fare_currency"].ToString() + "\t" + dt.Rows[i - 1]["price"].ToString() + "\t" + dt.Rows[i - 1]["surcharge"].ToString() + "\t" + dt.Rows[i - 1]["fare_roe"].ToString() + "\t");
            sb.Append( dt.Rows[i - 1]["tax_currency"].ToString() + "\t"+dt.Rows[i - 1]["taxes"].ToString() + "\t" + dt.Rows[i - 1]["tax_roe"].ToString() );

            sb.Append("\r\n");
        }
        Page.Response.Write(sb.ToString());
        Page.Response.End();
    }
}
